package leet.ku._191;

public class Solution {
	
	// you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        if (n >= 0)
        	return _positiveWeight(n);
        else
        	return 32 - _positiveWeight(~n);
    }
    
    private int _positiveWeight(int n) {
    	int ans = 0;
        while (n > 0) {
        	n -= n & -n;
        	ans++;
        }
        return ans;
    }

}
